package world.snowcrystal.component;

import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.stereotype.Component;
import world.snowcrystal.properties.AuthenticationProperties;

@Component
@ConditionalOnClass(AuthenticationProperties.class)
public class DefaultSnowcrystalPasswordGenerator implements PasswordGenerator {

    @Autowired
    private AuthenticationProperties properties;

    @Override
    public String generatePassword() {
        return RandomStringUtils.randomAlphanumeric(properties.getMinPasswordGenerationLength(), properties.getMaxPasswordGenerationLength());
    }
}
